<?php

namespace app\adminabc\controller;

use app\adminabc\controller\Base;

class Member extends Base {
	function index() {
		$type = $this->request->param ( 'type' );
		$kw = $this->request->param ( 'kw' );
		if ($this->request->isPost ()) {
			switch ($type) {
				case 1 :
					$map [] = [ 'user_id','=',$kw ];
					break;
				case 6 :
					$map [] = [ 'user_name','like',"%$kw%" ];
					break;
			}
		}
		$data = model ( 'Member' )->getlist ( $map );
		$this->assign ( 'data', $data );
		return $this->fetch ( 'list-member' );
	}
	function info() {
		// $map ['merchant_id'] = $this->_uid;
		$map [] = [ 'user_id','=',$this->request->param ( 'id' ) ];
		// $map ['w.yftid'] = $this->_yftid;
		$info = model ( 'Member' )->getInfo ( $map );
		if ($this->request->isPost ()) {
			$data ['wallet_type'] = $this->request->param ( 'wallet_type' );
			$data ['usdt_wallet'] = $this->request->param ( 'usdt_wallet' );
			$data ['key'] = $this->request->param ( 'key' );
			$data ['money'] = $this->request->param ( 'money' ) ?: 0;
			$data ['status'] = $this->request->param ( 'status' );
			$data ['role_id'] = $this->request->param ( 'role_id' );
			$data ['isinside'] = $this->request->param ( 'isinside' );
			$data ['frozen_remark'] = $this->request->param ( 'frozen_remark' ) == '' ? '' : $this->request->param ( 'frozen_remark' );
			$log = model ( 'Member' )->edit ( array ([ 'user_id','=',$info ['user_id'] ] ), $data );
			if ($log > 0)
				$this->success ( '更新成功' );
			else
				$this->error ( '更新失败' );
		} else {
			$this->assign ( 'info', $info );
			$this->assign ( 'role', model ( 'Member' )->getAllRole () );
			return $this->fetch ( 'member-info' );
		}
	}
/*	function del() {
		$id = $this->request->param ( 'id' );
		$map [] = [ 'user_id','=',$id ];
		$log = model ( 'Member' )->del ( $map );
		if ($log > 0)
			echo json_encode ( array ('status' => 'yes','msg' => '删除成功' ) );
		else
			echo json_encode ( array ('status' => 'no','msg' => '删除失败' ) );
	}*/
		function del() {
		$id = $this->request->param ( 'id' );
		$map [] = [ 'user_id','=',$id ];
		$log = model ( 'Member' )->del ( $map );
		if ($log > 0)
			echo json_encode ( array ('status' => 'yes','msg' => '删除成功' ) );
		else
			echo json_encode ( array ('status' => 'no','msg' => '删除失败' ) );
	}
	function role() {
		$kw = $this->request->param ( 'kw' );
		$map [] = [ 'title','like',"%$kw%" ];
		$data = model ( 'Member' )->getAllRole ( $map );
		$this->assign ( 'data', $data );
		return $this->fetch ( 'list-role' );
	}
	function addRole() {
		if ($this->request->isPost ()) {
			$sort_id = $this->request->param ( 'sort_id' );
			$info = model ( 'Member' )->roleInfo ( array ([ 'sort_id','=',$sort_id ] ) );
			if (count ( $info ) > 0)
				$this->error ( '该层级已存在' );
			$data ['title'] = $this->request->param ( 'title' );
			$data ['sort_id'] = $sort_id;
			$data ['create_time'] = time ();
			$data ['thumb'] = $this->request->param ( 'thumb' );
			$data ['status'] = $this->request->param ( 'status' );
			$data ['deposit'] = $this->request->param ( 'deposit' );
			$data ['daily_pay'] = $this->request->param ( 'daily_pay' );
			$data ['month_pay'] = $this->request->param ( 'month_pay' );
			$log = model ( 'Member' )->addRole ( $data );
			if ($log > 0)
				$this->success ( '添加成功' );
			else
				$this->error ( '添加失败' );
		} else {
			return $this->fetch ( 'add-role' );
		}
	}
	function editRole() {
		$id = $this->request->param ( 'id' );
		$roleInfo = model ( 'Member' )->roleInfo ( array ([ 'id','=',$id ] ) );
		if ($this->request->isPost ()) {
			$sort_id = $this->request->param ( 'sort_id' );
			$info = model ( 'Member' )->roleInfo ( array ([ 'sort_id','=',$sort_id ] ) );
			if (count ( $info ) > 0 && $info ['id'] != $roleInfo ['id'])
				$this->error ( '该层级已存在' );
			$data ['title'] = $this->request->param ( 'title' );
			$data ['status'] = $this->request->param ( 'status' );
			$data ['sort_id'] = $sort_id;
			$data ['thumb'] = $this->request->param ( 'thumb' );
			$data ['status'] = $this->request->param ( 'status' );
			$data ['deposit'] = $this->request->param ( 'deposit' );
			$data ['daily_pay'] = $this->request->param ( 'daily_pay' );
			$data ['month_pay'] = $this->request->param ( 'month_pay' );
			$log = model ( 'Member' )->editRole ( array ([ 'id','=',$roleInfo ['id'] ] ), $data );
			if ($log > 0)
				$this->success ( '修改成功' );
			else
				$this->error ( '修改失败' );
		} else {
			$this->assign ( 'roleInfo', $roleInfo );
			return $this->fetch ( 'add-role' );
		}
	}
	function delRole() {
		$id = $this->request->param ( 'id' );
		$log = model ( 'Member' )->delRole ( array ([ 'id','=',$id ] ) );
		if ($log > 0)
			echo json_encode ( array ('status' => 'yes','msg' => '删除成功' ) );
		else
			echo json_encode ( array ('status' => 'no','msg' => '删除失败' ) );
	}
}

?>